Welcome Guest | Sign in | Register

Home > Java Programming > Variables and Loops > Questions and Answers

01. What will be output of following program?

class StringLiteral{
public static void main(String[] args){
String str="local\national";
System.out.print(str);
}
}
A. Local \ National B. local ational
C. local
ational
D. Compiler error

Answer and Explanation

Answer: local
ational

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. public class TypeConversion {
public static void main(String[] args) {
double d=2D+2d+2.+2l+2L+2f+2F+2.f+2.D;
System.out.println(d);
}
}
A. 18.0 B. 9.0
C. Run time exception

D. Compiler error

Answer and Explanation

Answer: 18.0

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. public class UnaryOperator {
public static void main(String[] args) {
byte a=-5;
int b=-5;
int c=~a+(byte)~b;
System.out.print(c);
}
}

What will output when you compile and run the above code?
A. 0 B. 8
C. Run time exception D. Compiler error

Answer and Explanation

Answer: 8

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. public class BreakDemo {
public static void main(String[] args){
int j=~-3;

while(j<7){
System.out.print(j);

if(j==3){
j+=2;
continue;
}

j++;
}
}
}

What will be output of above program?
A. 2367 B. 23
C. 2356 D. Compiler error

Answer and Explanation

Answer: 2356

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What will be output of following program?

public class Datatype {
public static void main(String[] args) {
byte b=125;
System.out.println(b*2);
}
}
A. 250 B. -6
C. Runtime exception D. Compiler error

Answer and Explanation

Answer: 250

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. public class Identifier {
public static void main(String[] args) {
double strictfp=5.02;
strictfp+=.333;
System.out.print(strictfp);
}
}
A. 5.353 B. 5.353D
C. 5.353d D. Compiler error

Answer and Explanation

Answer: Compiler error

Explanation:
    In java programming language variable name includes alphabet, digits few special characters like underscore (_), dollar singe ($) but it should not be any reserved word of java language. Here strictfp is keyword of java cannot be name of variable

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. public class TypeConversion {
public static void main(String[] args) {
float f1=11;
float f2=11.f;
f2=f1+f2;
System.out.println(f2);
}
}

What will output when you compile and run the above code?
A. 22 B. 22.0
C. 22.0f D. Compiler error

Answer and Explanation

Answer: 22.0

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. public class Operator {
public static void main(String[] args) {
byte a=5;
int b=10;
int c=a>>2+b>>2;
System.out.print(c);
}
}

What will output when you compile and run the above code?
A. 60 B. 3
C. 0 D. Compiler error

Answer and Explanation

Answer: 0

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. class Mango{
final int a=5;
}

class Fruit extends Mango {
final int a=10;
}

class DynamicDispatch extends Fruit{
final int a=20;
public static void main(String[] args){
Mango m=new DynamicDispatch();
Fruit f=new DynamicDispatch();
System.out.print(m.a|f.a);
}
}

What will be output of above program?
A. 15 B. 20
C. 30 D. Compiler error

Answer and Explanation

Answer: 15

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Which is not true java statement?
A. Java deallocates memory automatically B. Finalize method is just called before garbage collection.
C. Garbage collection runs when there is reference with object and runs periodically. D. Inside finalize method we keep those code which must be executed before object is destroyed by garbage collection.

Answer and Explanation

Answer: Garbage collection runs when there is reference with object and runs periodically.

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
11. public class This {
int i;

This(){
this.i++;
i++;
}

public static void main(String[] args){
This o=new This();
System.out.print(o.i);
}
}

What will be output of above program?
A. Garbage value B. 1
C. 2 D. Non static variable must be initialized, Compiler error

Answer and Explanation

Answer: 2

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.